<template>
<div class=''>
  <el-button @click="startPolling">开始轮询</el-button>
  <el-button @click="stopPolling">停止轮询</el-button>
</div>
</template>

<script>

export default {
  name: 'polling',
  data () {
    return {
      pollingTimer: null
    }
  },
  methods: {
    // 轮询开始
    async startPolling () {
      await this.pollingOne()
      await this.pollingTwo()
      this.pollingTimer = setTimeout(this.startPolling, 60 * 1000)
    },
    // 停止轮询
    stopPolling () {
      if (this.pollingTimer) {
        clearTimeout(this.pollingTimer)
        this.pollingTimer = null
      }
    },
    pollingOne () {
      console.log('pollingOne...')
    },
    pollingTwo () {
      console.log('pollingTwo...')
    }
  }
}
</script>
<style lang='less' scoped>
</style>
